package com.menggudf.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.menggudf.model.Illness2Model;
import com.menggudf.model.IllnessModel;
import com.menggudf.model.ResultModel;
import com.menggudf.model.SystemAdminModel;
import com.menggudf.service.DiagnosisService;
import com.menggudf.service.IllnessService;

@Controller
@RequestMapping("/illOper")
public class IllOperController {
    
    @Autowired
    private IllnessService illnessService;
    
    @Autowired
    private DiagnosisService diagnosisService;
    
    
    /**  以下为前端常用对疾病的操作，和常用交互操作，详细请看业务逻辑  **/
    
    
    /**
     * 1,按性别/年龄  查找出对应的疾病
     * */
    @RequestMapping("/getIllnessBySexAndAge")
    @ResponseBody
    public Map<String, Object> getIllnessBySexAndAge(
            @RequestParam("sex") Integer sex,/*性别*/
            @RequestParam("age") Integer age/*年龄*/){
                return illnessService.getIllnessBySexAndAge(sex,age);
        
    }
    
    /**
     * 2,根据疾病id的list，和脉搏（血压或体温）
     * */
    @RequestMapping("/getIllnessByIdsAndSymptom")
    @ResponseBody
    public Map<String, Object> getIllnessByIdsAndSymptom(
            @RequestParam("ids") String ids,/*第一步返回的ID*/
            @RequestParam("symptom") String symptom,/*病症*/
            @RequestParam("value") Integer value/*数值*/){
                return illnessService.getIllnessByIdsAndSymptom(ids,symptom,value);
        
    }
    
    /**
     * 3,根据疾病id的list和部位查询
     * */
    @RequestMapping("/getIllnessByPart")
    @ResponseBody
    public Map<String, Object> getIllnessByPart(
            @RequestParam("ids") String ids,/*第二步返回的ID*/
            @RequestParam("part") String part/*数值*/){
                return illnessService.getIllnessByPart(ids,part);
        
    }
    
    /**
     * 4,根据疾病id的list，获取所有的这些疾病的病症
     * */
    @RequestMapping("getSymptomsByillList")
    @ResponseBody
    public Map<String, Object> getSymptomsByillList(
            @RequestParam("ids") String ids){
                return illnessService.getSymptomsByillList(ids);
        
    }
    
    /**
     * 5,根据病症symptom和疾病列表ids 
     * 获取病症的二级属性
     * */
/*    @RequestMapping("/getSymptoms")
    @ResponseBody
    public Map<String, Object> getSymptoms(
            @RequestParam("ids") String ids,
            @RequestParam("symptom") String symptom){
        return illnessService.getSymptoms(ids,symptom);
        
    }*/
    
    /**
     * 6,按疾病ID和症状继续查询具体病
     * 直至搜索出唯一的疾病
     * 疾病的唯一由前端控制（当疾病只剩下一种）
     * symptoms为之前已经搜索过的字段
     * 当疾病只有一种的时候，前端控制不再调用
     * */
    @RequestMapping("/getIllByIdAndsymptoms")
    @ResponseBody
    public Map<String, Object> getIllByIdAndsymptomsYes(
            @RequestParam("symptom") String symptom,
            @RequestParam(value="value",required=false) Integer value,
            @RequestParam(value="degree",required=false) String degree,
            @RequestParam(value="nature",required=false) String nature,
            @RequestParam(value="times",required=false) String times,
            @RequestParam(value="symptoms") String symptoms,
            @RequestParam("ids") String ids){
        return illnessService.getIllByIdAndsymptomsYes(
                symptom,symptoms,ids,value,degree,nature,times);
        
    }
    
    
/*    @RequestMapping("/getIllnessInParts")
    @ResponseBody
    public Map<String, Object> getIllnessInParts(
            @RequestParam("parts") String parts,
            @RequestParam("sex") int sex,
            @RequestParam("isInjured") int isInjured,
            @RequestParam("age") int diseaseAge,
            @RequestParam(value="temperature",required=false) String temperature,
            @RequestParam(value="sYS",required=false) String SYS,
            @RequestParam(value="dIA",required=false) String DIA,
            @RequestParam(value="pulse",required=false) String pulse,
            @RequestParam("type") int type){
                return illnessService.getIllnessInParts(parts,sex,isInjured,diseaseAge,temperature,SYS,DIA,pulse,type);
        
    }*/
    

    

    
    /**
     * ,按疾病ID和症状继续查询具体病
     * 直至搜索出唯一的疾病
     * 疾病的唯一由前端控制（当疾病只剩下一种）
     * symptoms为之前已经搜索过的字段
     * 当疾病只有一种的时候，前端控制不再调用
     * */
    @RequestMapping("/getIllByIdAndsymptomsYes")//废弃
    @ResponseBody
    public Map<String, Object> getIllByIdAndsymptoms(
            @RequestParam("symptom") String symptom,
            @RequestParam(value="temperature",required=false) String temperature,
            @RequestParam(value="sYS",required=false) String SYS,
            @RequestParam(value="dIA",required=false) String DIA,
            @RequestParam(value="pulse",required=false) String pulse,
            @RequestParam(value="degree",required=false) String degree,
            @RequestParam(value="nature",required=false) String nature,
            @RequestParam(value="times",required=false) String times,
            @RequestParam(value="symptoms") String symptoms,
            @RequestParam("ids") String ids){
        return illnessService.getIllByIdAndsymptoms(
                symptom,symptoms,ids,temperature,
                SYS,DIA,pulse,degree,nature,times);
        
    }
    
    /**
     * 当这种病症不存在(弃用)
     * */
    @RequestMapping("/getIllByIdAndsymptomsNo")
    @ResponseBody
    public Map<String, Object> getIllByIdAndsymptomsNo(
            @RequestParam("symptom") String symptom,
            @RequestParam(value="symptoms") String symptoms,
            @RequestParam("ids") String ids){
        return illnessService.getIllByIdAndsymptomsNo(symptom,symptoms,ids);
        
    }
    
    /**
     * 4,根据疾病的id获取对应的诊疗方案
     * */
    @RequestMapping("/getDiagnosisById")
    @ResponseBody
    public ResultModel getDiagnosisById(
            @RequestParam("id") String id){
        IllnessModel ill = illnessService.getIllnessById(id);
        return diagnosisService.getDiagnosisByIllnessId(ill.getIllness());
        
    }

    /**
     * 根据疾病id获取疾病
     * */
    @RequestMapping("/getIll2ById")
    @ResponseBody
    public Illness2Model getIll2ById(
            @RequestParam("id") String id){
        return illnessService.getIllness2ById(id);
        
    }
    
    /**
     * 根据疾病id获取疾病
     * */
    @RequestMapping("/deleteIll")
    @ResponseBody
    public ResultModel deleteIll(
            @RequestParam("illness") String illness,
            HttpSession httpSession){
        
        SystemAdminModel model = (SystemAdminModel) httpSession.getAttribute("SystemAdminModel");
        String author = model.getAdminName();
        if(!author.equalsIgnoreCase("superAdmin")){
            return ResultModel.fail("没有权限", null);
        }else{
            return illnessService.deleteIll(illness);
        }
        
    }
    
    @RequestMapping("/deleteSymptom")
    @ResponseBody
    public ResultModel deleteSymptom(
            @RequestParam("illness") String illness,
            HttpSession httpSession){
        
        SystemAdminModel model = (SystemAdminModel) httpSession.getAttribute("SystemAdminModel");
        String author = model.getAdminName();
        if(!author.equalsIgnoreCase("superAdmin")){
            return ResultModel.fail("没有权限", null);
        }else{
            return illnessService.deleteSymptom(illness);
        }
        
    }
    
    @RequestMapping("/deleteParts")
    @ResponseBody
    public ResultModel deleteParts(
            @RequestParam("illness") String illness,
            HttpSession httpSession){
        
        SystemAdminModel model = (SystemAdminModel) httpSession.getAttribute("SystemAdminModel");
        String author = model.getAdminName();
        if(!author.equalsIgnoreCase("superAdmin")){
            return ResultModel.fail("没有权限", null);
        }else{
            return illnessService.deleteParts(illness);
        }
        
    }
    
    //获取ids的辅助检查
    @RequestMapping("/getExamByillList")
    @ResponseBody
    public List<String> getExamByillList(
            @RequestParam("ids") String ids){
                return illnessService.getExamByillList(ids);
        
    }
    
/*    *//**
     * excel导入
     * @throws IOException 
     * *//*
    @RequestMapping("/importExcel")
    @ResponseBody
    public ResultModel importExcel(
            @RequestParam MultipartFile file,
            HttpServletRequest request, HttpServletResponse response) throws IOException{
         return illnessService.importExcel(file);
         
    }*/
    
}
